package com.example.student.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.domain.Result;
import com.example.common.domain.pojo.Classes;
import com.example.common.domain.pojo.Course;
import com.example.common.domain.pojo.Student;
import com.example.common.domain.pojo.Teacher;
import com.example.student.service.ClassesService;
import com.example.student.service.CourseService;
import com.example.student.service.StudentService;
import com.example.student.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(value = "学生端接口", description = "班级课程查看")
@RestController
@RefreshScope//时时刷新配置信息
@Slf4j  //日志  log.info("登录日志测试：");
@RequestMapping("/students")
@RequiredArgsConstructor
public class ClassCourseController {
    @Autowired
    private ClassesService classesService;
    @Autowired
    private CourseService courseService;
    @Autowired
    private StudentService studentService;
    @Autowired
    private TeacherService teacherService;

    @ApiOperation("班级查询")
    @GetMapping("/getClass/{id}")
    public Result<Classes> getClass(@PathVariable String id) {
        return Result.success(classesService.getClassesByStudentId(id));
    }

    @ApiOperation("班级课程列表查询")
    @GetMapping("/getClassCourseList/{classId}")
    public Result<List<Course>> getClassCourseList(@PathVariable String classId) {
        return Result.success(courseService.getCourseByClassId(classId));
    }

    @ApiOperation("课程查询")
    @GetMapping("/getCourse/{id}")
    public Result<Course> getCourse(@PathVariable String id) {
        return Result.success(courseService.getCourseByIdWithLogicalExpire(id));
    }

    @ApiOperation("分页查询班级人员")
    @GetMapping("/getClassStudentList/{classId}/{PageNum}/{PageSize}")
    public Result<Page<Student>> getClassStudentList(@PathVariable String classId, @PathVariable Integer PageNum, @PathVariable Integer PageSize) {
        return Result.success(classesService.getClassesStudentPage(classId, PageNum, PageSize));
    }

    @ApiOperation("查询同学信息")
    @GetMapping("/getStudentInfo/{id}")
    public Result<Student> getStudentInfo(@PathVariable String id) {
        return Result.success(studentService.getStudentByIdWithLogicalExpireId(id));
    }

    @ApiOperation("查询老师列表")
    @GetMapping("/getTeacherList")
    public Result<List<Teacher>> getTeacherList() {
        return Result.success(teacherService.list());
    }

    @ApiOperation("查询老师信息")
    @GetMapping("/getTeacherInfo/{id}")
    public Result<Teacher> getTeacherInfo(@PathVariable String id) {
        return Result.success(teacherService.getById(id));
    }


}
